package com.bupt.liutong.admin.shop.bo;

import java.util.List;

import com.bupt.liutong.admin.core.base.BaseBo;
import com.bupt.liutong.admin.shop.dao.CartDao;
import com.bupt.liutong.admin.shop.dto.Cart;
import com.bupt.liutong.admin.shop.form.CartForm;
import com.bupt.liutong.util.BeanUtils;

public class CartBo extends BaseBo {
	
	private CartDao cartDao;

	public void insertCart(CartForm cartForm) {
		Cart cart = new Cart();
		BeanUtils.copyProperties(cart, cartForm);
		Cart boughtProd = cartDao.getCartByProdId(cart);
		if (boughtProd == null || boughtProd.getProdNum() == 0)
			cartDao.insertCart(cart);
		else {
			boughtProd.setProdNum(boughtProd.getProdNum() + 1);
			cartDao.updateCart(boughtProd);
		}
	}
	
	public List<CartForm> getCarts(CartForm cartForm){
		Cart cart = new Cart();
		BeanUtils.copyProperties(cart, cartForm);
		List<Cart> Carts = cartDao.getCarts(cart);
		return BeanUtils.dtoToForm(Carts, CartForm.class);
	}

	public void setCartDao(CartDao cartDao) {
		this.cartDao = cartDao;
	}
}
